<template>
	<view class="flex-colume-start indexPage">
		<image style="margin-top: 20vh; width: 200rpx; height: 200rpx;" src="/static/home/logo1.jpeg"></image>
		<view style="margin-top: 45rpx; font-size: 30rpx;">颐和书院</view>

	</view>
</template>

<script>
	import {login,userInfo} from '@/api/api'
	export default {
		data() {
			return {
				shwoLogin:false
				
			}
		},
		onLoad() {
			var token = uni.getStorageSync('ele-mix-token')
			if (!token){
				this.showLogin = true
				this.toLogin()
			}else{
				userInfo().then(res=>{
					if (res.code != 200){
						this.showLogin = true
						this.toLogin()
						return
					}
					
					if (res.code == 200){
						uni.switchTab({
							url:'/pages/tab/index'
						})
						
					}
					
				}).catch(err=>{
					console.log('返回2')
				})
			}
			

		},
		onReady() {
			
		},

		methods: {
			toLogin(){
				uni.login({
					success: (res) => {
						setTimeout(res1 => {
							this.requestLogin(res.code)
						}, 500)
					},
					fail: () => {
						uni.hideLoading()
					}
					
				})
				
			},
			requestLogin(code){
				login({open_id_code:code}).then(res=>{
					if(res.code == 200){
						var data = res.data
						uni.setStorageSync('ele-mix-token',data.info.utoken)
						uni.switchTab({
							url:'/pages/tab/index'
						})
						return
						
					}
					this.showSimpleMessage(res.message)
					
				})
				
			}
			

		}
	}
</script>


<style lang="scss" scoped>
	.indexPage {
		width: 100vw;
		height: 100vh;
		background-color: white;
		font-size: 0px;
		

	}
</style>